﻿using System;
using UnityEngine;
using UnityEngine.Localization;
using UnityEngine.Localization.Tables;

/// <summary>
/// 语言数据管理
/// </summary>
public static class LanguageManager
{
    public static LocalizedStringTable CommonStringTable = new() { TableReference = "GeneralTextTable" };

    #region StringTable

    public static string GetLocalizedString(StringTable table, string entryName)
    {
        var entry = table.GetEntry(entryName);
        return entry.GetLocalizedString();
    }

    public static string GetLocalizedString(string entryName)
    {
        string localStringContent = "";
        try
        {
            localStringContent = GetLocalizedString(CommonStringTable.GetTable(), entryName);
        }
        catch (Exception ex)
        {
            Debug.LogError($"获取本地化文本失败:{entryName} - {ex}");
        }
        return localStringContent;
    }

    #endregion
}